home *** CD-ROM | disk | FTP | other *** search
- /*
- FILE: chebyshev.c
- PROJECT: Ford grant DSP
- AUTHOR: Ben Denckla
- COMMENT: nonlinear transfer function using Chebyshev polynomials of
- user-specified order.
- */
-
- #include "aiff.h"
- #include "sintab.h" // has the useful GETNUMRANGE() macro
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #define MAXORDER 16 // MAX. ORDER of chebyshev polynomial
- #define CILOG2 11 // see below
- #define CHECK_INC ( 1U << CILOG2 ) // period of progress report,
- // in table entries
- int take_input = 1, make_output = 1;
-
- static short *xferfunc;
-
- void init_process( void ) {
- short i, t, *txferfunc, order;
- double twox, *tp;
- double p[MAXORDER] = {1};
-
- if ( (ba.com.wdsi < 9) || (ba.com.wdsi > 16) )
- err( "Cannot process a file with this word size" );
-
- if (!(xferfunc = malloc( 0x20000 )))
- err( "Couldn't allocate transfer function table memory" );
-
- GETNUMRANGE( "order", "%hd", "%hd", order, 1, MAXORDER );
-
- puts( "Generating transfer function table..." );
- for (i=0; i < 0x10000 / CHECK_INC; i++) fputc( '*', stderr );
- fputc( '\n', stderr ); fflush( stderr );
-
- txferfunc = xferfunc;
- i = -0x8000;
- do {
- if (!(i % CHECK_INC)) { // progress report
- fputc( '*', stderr ); fflush( stderr );
- }
- tp = &p[1];
- *tp = (double) i / 0x8000;
- twox = *tp * 2;
-
- for ( t=2; t<=order; t++ ) {
- tp++;
- *tp = *(tp-1) * twox - *(tp-2);
- }
-
- *txferfunc++ = *tp * 0x7FFE; // 1
- } while ( i++ < 0x7FFF);
-
- puts( "\n\n" );
- }
- // 1. assumes |*tp|/1 <= 0x7FFF/0x7FFE
-
- void term_process ( void ) {
- free( xferfunc );
- }
-
- void process_samdat ( long buflen ) {
- register short *td, *endd, *txferfunc;
-
- td = d;
- txferfunc = xferfunc;
- endd = &td[ba.com.chan * buflen];
-
- do {
- *td++ = txferfunc[ 0x8000 + *td ];
- } while ( td < endd );
- }